package cn.zlb.frame.common.result;

/**
 * @author yangjie.deng@resico.cn
 * @date 2023-11-09 09:50:27
 * @describe class responsibility
 */
public class ResultBuilder {
    private static final int SUCCESS_CODE = 200;
    private static final int ERROR_CODE = 500;

    public static <T> Result<T> success() {
        return success(SUCCESS_CODE, "success");
    }

    public static <T> Result<T> success(String message) {
        return success(SUCCESS_CODE, message);
    }

    public static <T> Result<T> success(T data) {
        return build(SUCCESS_CODE, "success", data);
    }

    public static <T> Result<T> success(int code, String message) {
        return success(code, message, null);
    }

    public static <T> Result<T> success(int code, String message, T data) {
        return build(code, message, data);
    }

    public static <T> Result<T> error() {
        return error(ERROR_CODE, "failed");
    }

    public static <T> Result<T> error(String message) {
        return build(ERROR_CODE, message, null);
    }

    public static <T> Result<T> error(int code, String message) {
        return build(code, message, null);
    }

    private static <T> Result<T> build(int code, String msg, T data) {
        return new Result<>(code, msg, data);
    }
}
